package com.skyworth.web.wechat.repository;

import com.skyworth.web.wechat.entity.TableBindModel;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

/**
 * Created by yuhaichao on 2016/9/7.
 */
public interface TableBindRepository extends CrudRepository<TableBindModel,Long> {

    @Query(value="select id,user_id,table_id,state from ff_wx_table_bind where user_id=?1 and state=0 order by id desc limit 1",nativeQuery = true)
    public TableBindModel getTableBindByUserId(String userId);

    @Modifying
    @Query("update TableBindModel m set m.state =1 where m.state=0 and m.tableId = ?1")
    public void unbindTable(long tableid);

    @Modifying
    @Query("update TableBindModel m set m.state =1 where m.state=0 and m.userId = ?1")
    public void unbindTableByUserId(String userId);
}
